using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics.CodeAnalysis;
using System.Dynamic;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using Newtonsoft.Json.Converters;
using Newtonsoft.Json.Linq;
using ns16;
using ns20;

namespace Newtonsoft.Json.Serialization
{
	public class DefaultContractResolver : IContractResolver
	{
		[CompilerGenerated]
		private sealed class Class127
		{
			public Func<object, object> func_0;

			public Action<object, object> action_0;

			public Func<object> func_1;

			public Delegate3<object, object> delegate3_0;

			public void method_0(object object_0, string string_0, JToken jtoken_0)
			{
				object obj = func_0(object_0);
				if (obj == null)
				{
					obj = func_1();
					action_0(object_0, obj);
				}
				delegate3_0(obj, string_0, jtoken_0);
			}
		}

		[CompilerGenerated]
		private sealed class Class128
		{
			public Delegate3<object, object> delegate3_0;

			public object method_0(object[] object_0)
			{
				return delegate3_0(null, object_0);
			}
		}

		[CompilerGenerated]
		private sealed class Class129
		{
			public Delegate3<object, object> delegate3_0;

			public bool method_0(object object_0)
			{
				return (bool)delegate3_0(object_0);
			}
		}

		[CompilerGenerated]
		private sealed class Class130
		{
			public Func<object, object> func_0;

			public bool method_0(object object_0)
			{
				return (bool)func_0(object_0);
			}
		}

		private static readonly IContractResolver icontractResolver_0 = new DefaultContractResolver(shareCache: true);

		private static readonly IList<JsonConverter> ilist_0 = new List<JsonConverter>
		{
			new EntityKeyMemberConverter(),
			new ExpandoObjectConverter(),
			new XmlNodeConverter(),
			new BinaryConverter(),
			new DataSetConverter(),
			new DataTableConverter(),
			new KeyValuePairConverter(),
			new BsonObjectIdConverter(),
			new RegexConverter()
		};

		private static Dictionary<Struct27, JsonContract> dictionary_0;

		private static readonly object object_0 = new object();

		private Dictionary<Struct27, JsonContract> dictionary_1;

		private readonly bool bool_0;

		[CompilerGenerated]
		private BindingFlags bindingFlags_0;

		[CompilerGenerated]
		private bool bool_1;

		[CompilerGenerated]
		private bool bool_2;

		[CompilerGenerated]
		private bool bool_3;

		[CompilerGenerated]
		private static Func<MemberInfo, bool> func_0;

		[CompilerGenerated]
		private static Func<MemberInfo, bool> func_1;

		[CompilerGenerated]
		private static Func<ConstructorInfo, bool> func_2;

		[CompilerGenerated]
		private static Func<JsonProperty, int> func_3;

		internal static IContractResolver IContractResolver_0 => icontractResolver_0;

		public bool DynamicCodeGeneration => Class140.Boolean_0;

		public BindingFlags DefaultMembersSearchFlags
		{
			[CompilerGenerated]
			get
			{
				return bindingFlags_0;
			}
			[CompilerGenerated]
			set
			{
				bindingFlags_0 = value;
			}
		}

		public bool SerializeCompilerGeneratedMembers
		{
			[CompilerGenerated]
			get
			{
				return bool_1;
			}
			[CompilerGenerated]
			set
			{
				bool_1 = value;
			}
		}

		public bool IgnoreSerializableInterface
		{
			[CompilerGenerated]
			get
			{
				return bool_2;
			}
			[CompilerGenerated]
			set
			{
				bool_2 = value;
			}
		}

		public bool IgnoreSerializableAttribute
		{
			[CompilerGenerated]
			get
			{
				return bool_3;
			}
			[CompilerGenerated]
			set
			{
				bool_3 = value;
			}
		}

		public DefaultContractResolver()
			: this(shareCache: false)
		{
		}

		public DefaultContractResolver(bool shareCache)
		{
			DefaultMembersSearchFlags = BindingFlags.Instance | BindingFlags.Public;
			IgnoreSerializableAttribute = true;
			bool_0 = shareCache;
		}

		private Dictionary<Struct27, JsonContract> method_0()
		{
			if (bool_0)
			{
				return dictionary_0;
			}
			return dictionary_1;
		}

		private void method_1(Dictionary<Struct27, JsonContract> dictionary_2)
		{
			if (bool_0)
			{
				dictionary_0 = dictionary_2;
			}
			else
			{
				dictionary_1 = dictionary_2;
			}
		}

		public virtual JsonContract ResolveContract(Type type)
		{
			if (type == null)
			{
				throw new ArgumentNullException("type");
			}
			Struct27 key = new Struct27(GetType(), type);
			Dictionary<Struct27, JsonContract> dictionary = method_0();
			if (dictionary == null || !dictionary.TryGetValue(key, out var value))
			{
				value = CreateContract(type);
				lock (object_0)
				{
					dictionary = method_0();
					Dictionary<Struct27, JsonContract> dictionary2 = ((dictionary != null) ? new Dictionary<Struct27, JsonContract>(dictionary) : new Dictionary<Struct27, JsonContract>());
					dictionary2[key] = value;
					method_1(dictionary2);
					return value;
				}
			}
			return value;
		}

		protected virtual List<MemberInfo> GetSerializableMembers(Type objectType)
		{
			bool ignoreSerializableAttribute = IgnoreSerializableAttribute;
			MemberSerialization memberSerialization = Class140.smethod_7(objectType, ignoreSerializableAttribute);
			List<MemberInfo> list = (from memberInfo_0 in Class195.smethod_27(objectType, BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic)
				where !Class195.smethod_21(memberInfo_0)
				select memberInfo_0).ToList();
			List<MemberInfo> list2 = new List<MemberInfo>();
			if (memberSerialization != MemberSerialization.Fields)
			{
				DataContractAttribute dataContractAttribute = Class140.smethod_5(objectType);
				List<MemberInfo> list3 = (from memberInfo_0 in Class195.smethod_27(objectType, DefaultMembersSearchFlags)
					where !Class195.smethod_21(memberInfo_0)
					select memberInfo_0).ToList();
				foreach (MemberInfo item in list)
				{
					if (SerializeCompilerGeneratedMembers || !item.IsDefined(typeof(CompilerGeneratedAttribute), inherit: true))
					{
						if (list3.Contains(item))
						{
							list2.Add(item);
						}
						else if (Class140.smethod_17<JsonPropertyAttribute>(item) != null)
						{
							list2.Add(item);
						}
						else if (dataContractAttribute != null && Class140.smethod_17<DataMemberAttribute>(item) != null)
						{
							list2.Add(item);
						}
						else if (memberSerialization == MemberSerialization.Fields && item.smethod_1() == MemberTypes.Field)
						{
							list2.Add(item);
						}
					}
				}
				if (objectType.smethod_13("System.Data.Objects.DataClasses.EntityObject", out var _))
				{
					list2 = list2.Where(method_2).ToList();
				}
				return list2;
			}
			foreach (MemberInfo item2 in list)
			{
				FieldInfo fieldInfo = item2 as FieldInfo;
				if (fieldInfo != null && !fieldInfo.IsStatic)
				{
					list2.Add(item2);
				}
			}
			return list2;
		}

		private bool method_2(MemberInfo memberInfo_0)
		{
			PropertyInfo propertyInfo = memberInfo_0 as PropertyInfo;
			if (propertyInfo != null && propertyInfo.PropertyType.smethod_4() && propertyInfo.PropertyType.GetGenericTypeDefinition().FullName == "System.Data.Objects.DataClasses.EntityReference`1")
			{
				return false;
			}
			return true;
		}

		protected virtual JsonObjectContract CreateObjectContract(Type objectType)
		{
			JsonObjectContract jsonObjectContract = new JsonObjectContract(objectType);
			method_7(jsonObjectContract);
			bool ignoreSerializableAttribute = IgnoreSerializableAttribute;
			jsonObjectContract.MemberSerialization = Class140.smethod_7(jsonObjectContract.type_0, ignoreSerializableAttribute);
			jsonObjectContract.Properties.smethod_1(CreateProperties(jsonObjectContract.type_0, jsonObjectContract.MemberSerialization));
			JsonObjectAttribute jsonObjectAttribute = Class140.smethod_1(jsonObjectContract.type_0);
			if (jsonObjectAttribute != null)
			{
				jsonObjectContract.ItemRequired = jsonObjectAttribute.nullable_4;
			}
			ConstructorInfo constructorInfo = method_4(jsonObjectContract.type_0);
			if (constructorInfo != null)
			{
				jsonObjectContract.OverrideConstructor = constructorInfo;
				jsonObjectContract.ConstructorParameters.smethod_1(CreateConstructorParameters(constructorInfo, jsonObjectContract.Properties));
			}
			else if (jsonObjectContract.MemberSerialization == MemberSerialization.Fields)
			{
				if (Class140.Boolean_1)
				{
					jsonObjectContract.DefaultCreator = jsonObjectContract.method_5;
				}
			}
			else if (jsonObjectContract.DefaultCreator == null || jsonObjectContract.DefaultCreatorNonPublic)
			{
				ConstructorInfo constructorInfo2 = method_5(jsonObjectContract.type_0);
				if (constructorInfo2 != null)
				{
					jsonObjectContract.ParametrizedConstructor = constructorInfo2;
					jsonObjectContract.ConstructorParameters.smethod_1(CreateConstructorParameters(constructorInfo2, jsonObjectContract.Properties));
				}
			}
			jsonObjectContract.ExtensionDataSetter = method_3(jsonObjectContract.type_0);
			return jsonObjectContract;
		}

		private ExtensionDataSetter method_3(Type type_0)
		{
			ExtensionDataSetter result = null;
			foreach (Type item in method_10(type_0))
			{
				IList<MemberInfo> list = new List<MemberInfo>();
				list.smethod_1(item.GetProperties(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
				list.smethod_1(item.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic));
				foreach (MemberInfo item2 in list)
				{
					MemberTypes memberTypes = item2.smethod_1();
					if ((memberTypes != MemberTypes.Property && memberTypes != MemberTypes.Field) || !item2.IsDefined(typeof(JsonExtensionDataAttribute), inherit: false))
					{
						continue;
					}
					Type type = Class195.smethod_20(item2);
					if (Class195.smethod_14(type, typeof(IDictionary<, >), out var type_))
					{
						Type type2 = type_.GetGenericArguments()[0];
						Type type3 = type_.GetGenericArguments()[1];
						if (Class195.smethod_12(type, typeof(IDictionary<, >)))
						{
							type = typeof(Dictionary<, >).MakeGenericType(type2, type3);
						}
						if (type2.IsAssignableFrom(typeof(string)) && type3.IsAssignableFrom(typeof(JToken)))
						{
							MethodInfo method = type.GetMethod("Add", new Type[2] { type2, type3 });
							Func<object, object> func_0 = Class140.Class167_0.method_0<object>(item2);
							Action<object, object> action_0 = Class140.Class167_0.method_1<object>(item2);
							Func<object> func_1 = Class140.Class167_0.ns20_002EClass167_002E_206E_206D_200F_202C_202B_206A_206E_200E_202B_206A_206F_206A_202E_202C_206E_202D_202A_202D_202B_206F_206C_202D_206C_206C_202A_206E_200B_206A_202A_202C_206B_200C_206A_206A_200B_206D_206A_206E_200E_206E_202E<object>(type);
							Delegate3<object, object> delegate3_0 = Class140.Class167_0.ns20_002EClass167_002E_206A_206E_200E_202E_206E_200B_200B_200E_202C_206A_202A_202B_200C_206A_206C_206D_202B_200F_206E_200F_202C_200D_200D_202B_202B_206F_206D_206E_206D_206B_200B_206B_200B_200E_200D_202E_202A_206C_200F_202B_202E<object>(method);
							result = delegate(object object_0, string string_0, JToken jtoken_0)
							{
								object obj = func_0(object_0);
								if (obj == null)
								{
									obj = func_1();
									action_0(object_0, obj);
								}
								delegate3_0(obj, string_0, jtoken_0);
							};
							continue;
						}
					}
					throw new JsonException("Invalid extension data attribute on '{0}'. Member '{1}' type must implement IDictionary<string, JToken>.".smethod_1(CultureInfo.InvariantCulture, smethod_4(item2.DeclaringType), item2.Name));
				}
			}
			return result;
		}

		private ConstructorInfo method_4(Type type_0)
		{
			IList<ConstructorInfo> list = (from constructorInfo_0 in type_0.GetConstructors(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic)
				where constructorInfo_0.IsDefined(typeof(JsonConstructorAttribute), inherit: true)
				select constructorInfo_0).ToList();
			if (list.Count > 1)
			{
				throw new JsonException("Multiple constructors with the JsonConstructorAttribute.");
			}
			if (list.Count == 1)
			{
				return list[0];
			}
			if (type_0 == typeof(Version))
			{
				return type_0.GetConstructor(new Type[4]
				{
					typeof(int),
					typeof(int),
					typeof(int),
					typeof(int)
				});
			}
			return null;
		}

		private ConstructorInfo method_5(Type type_0)
		{
			IList<ConstructorInfo> list = type_0.GetConstructors(BindingFlags.Instance | BindingFlags.Public).ToList();
			if (list.Count == 1)
			{
				return list[0];
			}
			return null;
		}

		protected virtual IList<JsonProperty> CreateConstructorParameters(ConstructorInfo constructor, JsonPropertyCollection memberProperties)
		{
			ParameterInfo[] parameters = constructor.GetParameters();
			JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(constructor.DeclaringType);
			ParameterInfo[] array = parameters;
			foreach (ParameterInfo parameterInfo in array)
			{
				JsonProperty jsonProperty = ((parameterInfo.Name != null) ? memberProperties.GetClosestMatchProperty(parameterInfo.Name) : null);
				if (jsonProperty != null && jsonProperty.PropertyType != parameterInfo.ParameterType)
				{
					jsonProperty = null;
				}
				JsonProperty jsonProperty2 = CreatePropertyFromConstructorParameter(jsonProperty, parameterInfo);
				if (jsonProperty2 != null)
				{
					jsonPropertyCollection.AddProperty(jsonProperty2);
				}
			}
			return jsonPropertyCollection;
		}

		protected virtual JsonProperty CreatePropertyFromConstructorParameter(JsonProperty matchingMemberProperty, ParameterInfo parameterInfo)
		{
			JsonProperty jsonProperty = new JsonProperty();
			jsonProperty.PropertyType = parameterInfo.ParameterType;
			method_11(jsonProperty, parameterInfo, parameterInfo.Name, parameterInfo.Member.DeclaringType, MemberSerialization.OptOut, out var _);
			jsonProperty.Readable = false;
			jsonProperty.Writable = true;
			if (matchingMemberProperty != null)
			{
				jsonProperty.PropertyName = ((jsonProperty.PropertyName != parameterInfo.Name) ? jsonProperty.PropertyName : matchingMemberProperty.PropertyName);
				jsonProperty.Converter = jsonProperty.Converter ?? matchingMemberProperty.Converter;
				jsonProperty.MemberConverter = jsonProperty.MemberConverter ?? matchingMemberProperty.MemberConverter;
				if (!jsonProperty.bool_0 && matchingMemberProperty.bool_0)
				{
					jsonProperty.DefaultValue = matchingMemberProperty.DefaultValue;
				}
				jsonProperty.nullable_0 = jsonProperty.nullable_0 ?? matchingMemberProperty.nullable_0;
				jsonProperty.IsReference = jsonProperty.IsReference ?? matchingMemberProperty.IsReference;
				jsonProperty.NullValueHandling = jsonProperty.NullValueHandling ?? matchingMemberProperty.NullValueHandling;
				jsonProperty.DefaultValueHandling = jsonProperty.DefaultValueHandling ?? matchingMemberProperty.DefaultValueHandling;
				jsonProperty.ReferenceLoopHandling = jsonProperty.ReferenceLoopHandling ?? matchingMemberProperty.ReferenceLoopHandling;
				jsonProperty.ObjectCreationHandling = jsonProperty.ObjectCreationHandling ?? matchingMemberProperty.ObjectCreationHandling;
				jsonProperty.TypeNameHandling = jsonProperty.TypeNameHandling ?? matchingMemberProperty.TypeNameHandling;
			}
			return jsonProperty;
		}

		protected virtual JsonConverter ResolveContractConverter(Type objectType)
		{
			return Class140.smethod_10(objectType, objectType);
		}

		private Func<object> method_6(Type type_0)
		{
			return Class140.Class167_0.ns20_002EClass167_002E_206E_206D_200F_202C_202B_206A_206E_200E_202B_206A_206F_206A_202E_202C_206E_202D_202A_202D_202B_206F_206C_202D_206C_206C_202A_206E_200B_206A_202A_202C_206B_200C_206A_206A_200B_206D_206A_206E_200E_206E_202E<object>(type_0);
		}

		[SuppressMessage("Microsoft.Portability", "CA1903:UseOnlyApiFromTargetedFramework", MessageId = "System.Runtime.Serialization.DataContractAttribute.#get_IsReference()")]
		private void method_7(JsonContract jsonContract_0)
		{
			JsonContainerAttribute jsonContainerAttribute = Class140.smethod_0(jsonContract_0.type_0);
			if (jsonContainerAttribute != null)
			{
				jsonContract_0.IsReference = jsonContainerAttribute.nullable_0;
			}
			else
			{
				DataContractAttribute dataContractAttribute = Class140.smethod_5(jsonContract_0.type_0);
				if (dataContractAttribute != null && dataContractAttribute.IsReference)
				{
					jsonContract_0.IsReference = true;
				}
			}
			jsonContract_0.Converter = ResolveContractConverter(jsonContract_0.type_0);
			jsonContract_0.JsonConverter_0 = JsonSerializer.smethod_1(ilist_0, jsonContract_0.type_0);
			if (Class195.smethod_6(jsonContract_0.CreatedType, bool_0: true) || jsonContract_0.CreatedType.smethod_12())
			{
				jsonContract_0.DefaultCreator = method_6(jsonContract_0.CreatedType);
				jsonContract_0.DefaultCreatorNonPublic = !jsonContract_0.CreatedType.smethod_12() && Class195.smethod_7(jsonContract_0.CreatedType) == null;
			}
			method_8(jsonContract_0, jsonContract_0.type_0);
		}

		private void method_8(JsonContract jsonContract_0, Type type_0)
		{
			method_9(type_0, out var list_, out var list_2, out var list_3, out var list_4, out var list_5);
			if (list_ != null)
			{
				jsonContract_0.OnSerializingCallbacks.smethod_1(list_);
			}
			if (list_2 != null)
			{
				jsonContract_0.OnSerializedCallbacks.smethod_1(list_2);
			}
			if (list_3 != null)
			{
				jsonContract_0.OnDeserializingCallbacks.smethod_1(list_3);
			}
			if (list_4 != null && (!type_0.smethod_4() || type_0.GetGenericTypeDefinition() != typeof(ConcurrentDictionary<, >)))
			{
				jsonContract_0.OnDeserializedCallbacks.smethod_1(list_4);
			}
			if (list_5 != null)
			{
				jsonContract_0.OnErrorCallbacks.smethod_1(list_5);
			}
		}

		private void method_9(Type type_0, out List<SerializationCallback> list_0, out List<SerializationCallback> list_1, out List<SerializationCallback> list_2, out List<SerializationCallback> list_3, out List<SerializationErrorCallback> list_4)
		{
			list_0 = null;
			list_1 = null;
			list_2 = null;
			list_3 = null;
			list_4 = null;
			foreach (Type item in method_10(type_0))
			{
				MethodInfo methodInfo_ = null;
				MethodInfo methodInfo_2 = null;
				MethodInfo methodInfo_3 = null;
				MethodInfo methodInfo_4 = null;
				MethodInfo methodInfo_5 = null;
				MethodInfo[] methods = item.GetMethods(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (!methodInfo.ContainsGenericParameters)
					{
						Type type_ = null;
						ParameterInfo[] parameters = methodInfo.GetParameters();
						if (smethod_3(methodInfo, parameters, typeof(OnSerializingAttribute), methodInfo_, ref type_))
						{
							list_0 = list_0 ?? new List<SerializationCallback>();
							list_0.Add(JsonContract.smethod_0(methodInfo));
							methodInfo_ = methodInfo;
						}
						if (smethod_3(methodInfo, parameters, typeof(OnSerializedAttribute), methodInfo_2, ref type_))
						{
							list_1 = list_1 ?? new List<SerializationCallback>();
							list_1.Add(JsonContract.smethod_0(methodInfo));
							methodInfo_2 = methodInfo;
						}
						if (smethod_3(methodInfo, parameters, typeof(OnDeserializingAttribute), methodInfo_3, ref type_))
						{
							list_2 = list_2 ?? new List<SerializationCallback>();
							list_2.Add(JsonContract.smethod_0(methodInfo));
							methodInfo_3 = methodInfo;
						}
						if (smethod_3(methodInfo, parameters, typeof(OnDeserializedAttribute), methodInfo_4, ref type_))
						{
							list_3 = list_3 ?? new List<SerializationCallback>();
							list_3.Add(JsonContract.smethod_0(methodInfo));
							methodInfo_4 = methodInfo;
						}
						if (smethod_3(methodInfo, parameters, typeof(OnErrorAttribute), methodInfo_5, ref type_))
						{
							list_4 = list_4 ?? new List<SerializationErrorCallback>();
							list_4.Add(JsonContract.smethod_1(methodInfo));
							methodInfo_5 = methodInfo;
						}
					}
				}
			}
		}

		private List<Type> method_10(Type type_0)
		{
			List<Type> list = new List<Type>();
			Type type = type_0;
			while (type != null && type != typeof(object))
			{
				list.Add(type);
				type = type.smethod_6();
			}
			list.Reverse();
			return list;
		}

		protected virtual JsonDictionaryContract CreateDictionaryContract(Type objectType)
		{
			JsonDictionaryContract jsonDictionaryContract = new JsonDictionaryContract(objectType);
			method_7(jsonDictionaryContract);
			jsonDictionaryContract.PropertyNameResolver = ResolvePropertyName;
			return jsonDictionaryContract;
		}

		protected virtual JsonArrayContract CreateArrayContract(Type objectType)
		{
			JsonArrayContract jsonArrayContract = new JsonArrayContract(objectType);
			method_7(jsonArrayContract);
			return jsonArrayContract;
		}

		protected virtual JsonPrimitiveContract CreatePrimitiveContract(Type objectType)
		{
			JsonPrimitiveContract jsonPrimitiveContract = new JsonPrimitiveContract(objectType);
			method_7(jsonPrimitiveContract);
			return jsonPrimitiveContract;
		}

		protected virtual JsonLinqContract CreateLinqContract(Type objectType)
		{
			JsonLinqContract jsonLinqContract = new JsonLinqContract(objectType);
			method_7(jsonLinqContract);
			return jsonLinqContract;
		}

		protected virtual JsonISerializableContract CreateISerializableContract(Type objectType)
		{
			JsonISerializableContract jsonISerializableContract = new JsonISerializableContract(objectType);
			method_7(jsonISerializableContract);
			ConstructorInfo constructor = jsonISerializableContract.type_0.GetConstructor(BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
			{
				typeof(SerializationInfo),
				typeof(StreamingContext)
			}, null);
			if (constructor != null)
			{
				Delegate3<object, object> delegate3_0 = Class140.Class167_0.ns20_002EClass167_002E_206A_206E_200E_202E_206E_200B_200B_200E_202C_206A_202A_202B_200C_206A_206C_206D_202B_200F_206E_200F_202C_200D_200D_202B_202B_206F_206D_206E_206D_206B_200B_206B_200B_200E_200D_202E_202A_206C_200F_202B_202E<object>(constructor);
				jsonISerializableContract.ISerializableCreator = (object[] object_0) => delegate3_0(null, object_0);
			}
			return jsonISerializableContract;
		}

		protected virtual JsonDynamicContract CreateDynamicContract(Type objectType)
		{
			JsonDynamicContract jsonDynamicContract = new JsonDynamicContract(objectType);
			method_7(jsonDynamicContract);
			jsonDynamicContract.PropertyNameResolver = ResolvePropertyName;
			jsonDynamicContract.Properties.smethod_1(CreateProperties(objectType, MemberSerialization.OptOut));
			return jsonDynamicContract;
		}

		protected virtual JsonStringContract CreateStringContract(Type objectType)
		{
			JsonStringContract jsonStringContract = new JsonStringContract(objectType);
			method_7(jsonStringContract);
			return jsonStringContract;
		}

		protected virtual JsonContract CreateContract(Type objectType)
		{
			Type type = Class195.smethod_11(objectType);
			if (smethod_0(objectType))
			{
				return CreatePrimitiveContract(objectType);
			}
			if (Class140.smethod_1(type) != null)
			{
				return CreateObjectContract(objectType);
			}
			if (Class140.smethod_2(type) != null)
			{
				return CreateArrayContract(objectType);
			}
			if (Class140.smethod_3(type) != null)
			{
				return CreateDictionaryContract(objectType);
			}
			if (!(type == typeof(JToken)) && !type.IsSubclassOf(typeof(JToken)))
			{
				if (Class192.smethod_2(type))
				{
					return CreateDictionaryContract(objectType);
				}
				if (typeof(IEnumerable).IsAssignableFrom(type))
				{
					return CreateArrayContract(objectType);
				}
				if (smethod_2(type))
				{
					return CreateStringContract(objectType);
				}
				if (!IgnoreSerializableInterface && typeof(ISerializable).IsAssignableFrom(type))
				{
					return CreateISerializableContract(objectType);
				}
				if (typeof(IDynamicMetaObjectProvider).IsAssignableFrom(type))
				{
					return CreateDynamicContract(objectType);
				}
				if (smethod_1(type))
				{
					return CreatePrimitiveContract(type);
				}
				return CreateObjectContract(objectType);
			}
			return CreateLinqContract(objectType);
		}

		internal static bool smethod_0(Type type_0)
		{
			Enum17 @enum = Class182.smethod_0(type_0);
			if (@enum != 0)
			{
				return @enum != Enum17.Object;
			}
			return false;
		}

		internal static bool smethod_1(Type type_0)
		{
			if (!typeof(IConvertible).IsAssignableFrom(type_0) && (!Class195.smethod_10(type_0) || !typeof(IConvertible).IsAssignableFrom(Nullable.GetUnderlyingType(type_0))))
			{
				return false;
			}
			return !typeof(JToken).IsAssignableFrom(type_0);
		}

		internal static bool smethod_2(Type type_0)
		{
			TypeConverter typeConverter = Class182.smethod_13(type_0);
			if (typeConverter != null && !(typeConverter is ComponentConverter) && !(typeConverter is ReferenceConverter) && typeConverter.GetType() != typeof(TypeConverter) && typeConverter.CanConvertTo(typeof(string)))
			{
				return true;
			}
			if (!(type_0 == typeof(Type)) && !type_0.IsSubclassOf(typeof(Type)))
			{
				return false;
			}
			return true;
		}

		private static bool smethod_3(MethodInfo methodInfo_0, ParameterInfo[] parameterInfo_0, Type type_0, MethodInfo methodInfo_1, ref Type type_1)
		{
			if (!methodInfo_0.IsDefined(type_0, inherit: false))
			{
				return false;
			}
			if (methodInfo_1 != null)
			{
				throw new JsonException("Invalid attribute. Both '{0}' and '{1}' in type '{2}' have '{3}'.".smethod_3(CultureInfo.InvariantCulture, methodInfo_0, methodInfo_1, smethod_4(methodInfo_0.DeclaringType), type_0));
			}
			if (type_1 != null)
			{
				throw new JsonException("Invalid Callback. Method '{3}' in type '{2}' has both '{0}' and '{1}'.".smethod_3(CultureInfo.InvariantCulture, type_1, type_0, smethod_4(methodInfo_0.DeclaringType), methodInfo_0));
			}
			if (methodInfo_0.IsVirtual)
			{
				throw new JsonException("Virtual Method '{0}' of type '{1}' cannot be marked with '{2}' attribute.".smethod_2(CultureInfo.InvariantCulture, methodInfo_0, smethod_4(methodInfo_0.DeclaringType), type_0));
			}
			if (methodInfo_0.ReturnType != typeof(void))
			{
				throw new JsonException("Serialization Callback '{1}' in type '{0}' must return void.".smethod_1(CultureInfo.InvariantCulture, smethod_4(methodInfo_0.DeclaringType), methodInfo_0));
			}
			if (type_0 == typeof(OnErrorAttribute))
			{
				if (parameterInfo_0 == null || parameterInfo_0.Length != 2 || parameterInfo_0[0].ParameterType != typeof(StreamingContext) || parameterInfo_0[1].ParameterType != typeof(ErrorContext))
				{
					throw new JsonException("Serialization Error Callback '{1}' in type '{0}' must have two parameters of type '{2}' and '{3}'.".smethod_3(CultureInfo.InvariantCulture, smethod_4(methodInfo_0.DeclaringType), methodInfo_0, typeof(StreamingContext), typeof(ErrorContext)));
				}
			}
			else if (parameterInfo_0 == null || parameterInfo_0.Length != 1 || parameterInfo_0[0].ParameterType != typeof(StreamingContext))
			{
				throw new JsonException("Serialization Callback '{1}' in type '{0}' must have a single parameter of type '{2}'.".smethod_2(CultureInfo.InvariantCulture, smethod_4(methodInfo_0.DeclaringType), methodInfo_0, typeof(StreamingContext)));
			}
			type_1 = type_0;
			return true;
		}

		internal static string smethod_4(Type type_0)
		{
			if (!type_0.smethod_5() && type_0.smethod_2())
			{
				return string.Format(CultureInfo.InvariantCulture, "{0}.{1}", new object[2] { type_0.Namespace, type_0.Name });
			}
			return type_0.FullName;
		}

		protected virtual IList<JsonProperty> CreateProperties(Type type, MemberSerialization memberSerialization)
		{
			List<MemberInfo> serializableMembers = GetSerializableMembers(type);
			if (serializableMembers == null)
			{
				throw new JsonSerializationException("Null collection of seralizable members returned.");
			}
			JsonPropertyCollection jsonPropertyCollection = new JsonPropertyCollection(type);
			foreach (MemberInfo item in serializableMembers)
			{
				JsonProperty jsonProperty = CreateProperty(item, memberSerialization);
				if (jsonProperty != null)
				{
					jsonPropertyCollection.AddProperty(jsonProperty);
				}
			}
			return jsonPropertyCollection.OrderBy((JsonProperty jsonProperty_0) => jsonProperty_0.Order ?? (-1)).ToList();
		}

		protected virtual IValueProvider CreateMemberValueProvider(MemberInfo member)
		{
			if (DynamicCodeGeneration)
			{
				return new DynamicValueProvider(member);
			}
			return new ReflectionValueProvider(member);
		}

		protected virtual JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
		{
			JsonProperty jsonProperty = new JsonProperty();
			jsonProperty.PropertyType = Class195.smethod_20(member);
			jsonProperty.DeclaringType = member.DeclaringType;
			jsonProperty.ValueProvider = CreateMemberValueProvider(member);
			method_11(jsonProperty, member, member.Name, member.DeclaringType, memberSerialization, out var bool_);
			if (memberSerialization != MemberSerialization.Fields)
			{
				jsonProperty.Readable = Class195.smethod_25(member, bool_);
				jsonProperty.Writable = Class195.smethod_26(member, bool_, jsonProperty.HasMemberAttribute);
			}
			else
			{
				jsonProperty.Readable = true;
				jsonProperty.Writable = true;
			}
			jsonProperty.ShouldSerialize = method_12(member);
			method_13(jsonProperty, member, bool_);
			return jsonProperty;
		}

		private void method_11(JsonProperty jsonProperty_0, object object_1, string string_0, Type type_0, MemberSerialization memberSerialization_0, out bool bool_4)
		{
			DataContractAttribute dataContractAttribute = Class140.smethod_5(type_0);
			MemberInfo memberInfo = object_1 as MemberInfo;
			DataMemberAttribute dataMemberAttribute = ((dataContractAttribute == null || !(memberInfo != null)) ? null : Class140.smethod_6(memberInfo));
			JsonPropertyAttribute jsonPropertyAttribute = Class140.smethod_17<JsonPropertyAttribute>(object_1);
			if (jsonPropertyAttribute != null)
			{
				jsonProperty_0.HasMemberAttribute = true;
			}
			string propertyName = ((jsonPropertyAttribute != null && jsonPropertyAttribute.PropertyName != null) ? jsonPropertyAttribute.PropertyName : ((dataMemberAttribute == null || dataMemberAttribute.Name == null) ? string_0 : dataMemberAttribute.Name));
			jsonProperty_0.PropertyName = ResolvePropertyName(propertyName);
			jsonProperty_0.UnderlyingName = string_0;
			bool flag = false;
			if (jsonPropertyAttribute != null)
			{
				jsonProperty_0.nullable_0 = jsonPropertyAttribute.nullable_7;
				jsonProperty_0.Order = jsonPropertyAttribute.nullable_6;
				jsonProperty_0.DefaultValueHandling = jsonPropertyAttribute.nullable_1;
				flag = true;
			}
			else if (dataMemberAttribute != null)
			{
				jsonProperty_0.nullable_0 = (dataMemberAttribute.IsRequired ? Required.AllowNull : Required.Default);
				jsonProperty_0.Order = ((dataMemberAttribute.Order != -1) ? new int?(dataMemberAttribute.Order) : null);
				jsonProperty_0.DefaultValueHandling = ((!dataMemberAttribute.EmitDefaultValue) ? new DefaultValueHandling?(DefaultValueHandling.Ignore) : null);
				flag = true;
			}
			bool flag2 = Class140.smethod_17<JsonIgnoreAttribute>(object_1) != null || Class140.smethod_17<JsonExtensionDataAttribute>(object_1) != null || Class140.smethod_17<NonSerializedAttribute>(object_1) != null;
			if (memberSerialization_0 != MemberSerialization.OptIn)
			{
				bool flag3 = false;
				flag3 = Class140.smethod_17<IgnoreDataMemberAttribute>(object_1) != null;
				jsonProperty_0.Ignored = flag2 || flag3;
			}
			else
			{
				jsonProperty_0.Ignored = flag2 || !flag;
			}
			jsonProperty_0.Converter = Class140.smethod_10(object_1, jsonProperty_0.PropertyType);
			jsonProperty_0.MemberConverter = Class140.smethod_10(object_1, jsonProperty_0.PropertyType);
			DefaultValueAttribute defaultValueAttribute = Class140.smethod_17<DefaultValueAttribute>(object_1);
			if (defaultValueAttribute != null)
			{
				jsonProperty_0.DefaultValue = defaultValueAttribute.Value;
			}
			jsonProperty_0.NullValueHandling = jsonPropertyAttribute?.nullable_0;
			jsonProperty_0.ReferenceLoopHandling = jsonPropertyAttribute?.nullable_2;
			jsonProperty_0.ObjectCreationHandling = jsonPropertyAttribute?.nullable_3;
			jsonProperty_0.TypeNameHandling = jsonPropertyAttribute?.nullable_4;
			jsonProperty_0.IsReference = jsonPropertyAttribute?.nullable_5;
			jsonProperty_0.ItemIsReference = jsonPropertyAttribute?.nullable_8;
			jsonProperty_0.ItemConverter = ((jsonPropertyAttribute == null || !(jsonPropertyAttribute.ItemConverterType != null)) ? null : JsonConverterAttribute.smethod_0(jsonPropertyAttribute.ItemConverterType));
			jsonProperty_0.ItemReferenceLoopHandling = jsonPropertyAttribute?.nullable_9;
			jsonProperty_0.ItemTypeNameHandling = jsonPropertyAttribute?.nullable_10;
			bool_4 = false;
			if ((DefaultMembersSearchFlags & BindingFlags.NonPublic) == BindingFlags.NonPublic)
			{
				bool_4 = true;
			}
			if (jsonPropertyAttribute != null)
			{
				bool_4 = true;
			}
			if (memberSerialization_0 == MemberSerialization.Fields)
			{
				bool_4 = true;
			}
			if (dataMemberAttribute != null)
			{
				bool_4 = true;
				jsonProperty_0.HasMemberAttribute = true;
			}
		}

		private Predicate<object> method_12(MemberInfo memberInfo_0)
		{
			MethodInfo method = memberInfo_0.DeclaringType.GetMethod("ShouldSerialize" + memberInfo_0.Name, Class195.type_0);
			if (!(method == null) && !(method.ReturnType != typeof(bool)))
			{
				Delegate3<object, object> delegate3_0 = Class140.Class167_0.ns20_002EClass167_002E_206A_206E_200E_202E_206E_200B_200B_200E_202C_206A_202A_202B_200C_206A_206C_206D_202B_200F_206E_200F_202C_200D_200D_202B_202B_206F_206D_206E_206D_206B_200B_206B_200B_200E_200D_202E_202A_206C_200F_202B_202E<object>(method);
				return (object object_0) => (bool)delegate3_0(object_0);
			}
			return null;
		}

		private void method_13(JsonProperty jsonProperty_0, MemberInfo memberInfo_0, bool bool_4)
		{
			MemberInfo memberInfo = memberInfo_0.DeclaringType.GetProperty(memberInfo_0.Name + "Specified");
			if (memberInfo == null)
			{
				memberInfo = memberInfo_0.DeclaringType.GetField(memberInfo_0.Name + "Specified");
			}
			if (!(memberInfo == null) && !(Class195.smethod_20(memberInfo) != typeof(bool)))
			{
				Func<object, object> func_0 = Class140.Class167_0.method_0<object>(memberInfo);
				jsonProperty_0.GetIsSpecified = (object object_0) => (bool)func_0(object_0);
				if (Class195.smethod_26(memberInfo, bool_4, bool_1: false))
				{
					jsonProperty_0.SetIsSpecified = Class140.Class167_0.method_1<object>(memberInfo);
				}
			}
		}

		protected internal virtual string ResolvePropertyName(string propertyName)
		{
			return propertyName;
		}

		public string GetResolvedPropertyName(string propertyName)
		{
			return ResolvePropertyName(propertyName);
		}

		[CompilerGenerated]
		private static bool smethod_5(MemberInfo memberInfo_0)
		{
			return !Class195.smethod_21(memberInfo_0);
		}

		[CompilerGenerated]
		private static bool smethod_6(MemberInfo memberInfo_0)
		{
			return !Class195.smethod_21(memberInfo_0);
		}

		[CompilerGenerated]
		private static bool smethod_7(ConstructorInfo constructorInfo_0)
		{
			return constructorInfo_0.IsDefined(typeof(JsonConstructorAttribute), inherit: true);
		}

		[CompilerGenerated]
		private static int smethod_8(JsonProperty jsonProperty_0)
		{
			return jsonProperty_0.Order ?? (-1);
		}
	}
}
